/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.impl;

import com.ivanbiz.dao.BarangDAO;
import com.ivanbiz.model.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author User
 */
public class BarangDAOImpl extends GenericDAOImpl implements BarangDAO {

    @Override
    public List getDataByLike(Class clasImpl, String variable, Object input) throws Exception {
        try {
            Session session = HibernateUtil.getSession();
            Query query = session.createQuery("from com.ivanbiz.model.Barang b " +
                    "where str(b." + variable + ") like :input");
            query.setParameter("input", "%" + input + "%");
            List list = query.list();
            return list;
        } catch (Exception e) {
            HibernateUtil.rollbackTransaction();
            throw e;
        } finally {
            HibernateUtil.closeSession();
        }
    }
}
